/*
 * @Author: szx
 * @Date: 2022-05-18 13:42:38
 * @LastEditTime: 2022-05-18 13:54:57
 * @Description: 
 * @FilePath: \leetcode\面试题\04\08\08.js
 */
/**
 * @param {TreeNode} root
 * @param {TreeNode} p
 * @param {TreeNode} q
 * @return {TreeNode}
 */
 var lowestCommonAncestor = function(root, p, q) {
    if (root == p || root == q || root == null) return root;
    const resLeft = lowestCommonAncestor(root.left,p,q);
    const resRight = lowestCommonAncestor(root.right,p,q);
    if (resLeft && resRight) return root;
    if (resLeft) return resLeft;
    if (resRight) return resRight;
    return null;
};